/* Vlcmm plugin */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "about.hh"

#include <gtkmm/notebook.h>
#include <gtkmm/stock.h>
#include <gtkmm/textbuffer.h>
#include <gtkmm/textview.h>
#include <gtkmm/scrolledwindow.h>

#include <vlc/vlc.h>
#include <vlc_about.h>

#include "pixmaps/resources.h"
#include "util/string.hh"

AboutDialog::AboutDialog (Gtk::Window *parent) : m_toplevel (parent)
{

  if (m_toplevel)
    set_transient_for (*m_toplevel);

  set_title (_("About"));
  set_has_separator (false);
  set_border_width (2);

  // - - - - - -

  Gtk::HBox *hbox = new Gtk::HBox (false, 4);
  hbox->set_border_width (4);

  Gtk::Image *image = new Gtk::Image (Gdk::Pixbuf::create_from_file (gtr (config_GetDataDir ())+"/vlc32x32.png"));
  hbox->pack_start (*Gtk::manage (image), false, false);
  hbox->pack_start (*new Gtk::Label (gtr(_("VLC media player ")) + VERSION_MESSAGE), false, false);

  get_vbox ()->pack_start (*Gtk::manage (hbox), false, false);

  // - - - - - -

  Gtk::Notebook *notebook = new Gtk::Notebook ();
  notebook->append_page (*Gtk::manage (AboutDialog::create_info_tab ()), _("General Info"), true);
  notebook->append_page (*Gtk::manage (AboutDialog::create_authors_tab ()), _("Authors"), true);
  notebook->append_page (*Gtk::manage (AboutDialog::create_thanks_tab ()), _("Thanks"), true);
  notebook->append_page (*Gtk::manage (AboutDialog::create_license_tab ()), _("Distribution License"), true);

  get_vbox ()->pack_start (*Gtk::manage (notebook));

  // - - - - - -

  add_button (Gtk::Stock::CLOSE, Gtk::RESPONSE_CANCEL)->signal_clicked ().connect (sigc::mem_fun (this, &AboutDialog::close));

  // - - - - - -

  show_all ();

}

AboutDialog::~AboutDialog ()
{}

void
AboutDialog::close ()
{

  delete this;

}

Gtk::VBox*
AboutDialog::create_info_tab ()
{
  
  Gtk::VBox *vbox = new Gtk::VBox (false, 4);
  vbox->set_border_width (4);

  Gtk::HBox *hbox = new Gtk::HBox (false, 4);

  Gtk::Image *image = new Gtk::Image (Gdk::Pixbuf::create_from_file (gtr (config_GetDataDir ())+"/vlc128x128.png"));
  hbox->pack_start (*Gtk::manage (image), false, false);

  std::string str = gtr (_("VLC media player is a free media player, "
                           "encoder and streamer that can read from files, "
                           "CDs, DVDs, network streams, capture cards and even more!\n"
                           "Also, VLC works on essentially every popular platform.\n\n"))
                           + gtr (_("This version of VLC was compiled by:\n "))
                           + gtr (VLC_CompileBy ())+ "@" + gtr (VLC_CompileHost ()) + "."
                           + gtr (VLC_CompileDomain ()) + ".\n"
                           + "Compiler: " + gtr (VLC_Compiler ()) + ".\n"
                           + gtr (_("Based on Git commit: ")) + gtr (VLC_Changeset ()) + ".\n"
                           + gtr (_("You are using the GTK / GTKMM Interface.\n\n"))
                           + gtr (_("Copyright (c) " COPYRIGHT_YEARS " by the VideoLAN Team.\n"))
                           + "vlc@videolan.org, http://www.videolan.org";
  Gtk::Label *label = new Gtk::Label (str);
  label->set_line_wrap (true);
  label->set_size_request (520-128-2*4);
//    label->set_selectable (true);

  hbox->pack_start (*Gtk::manage (label), false, false);

  vbox->pack_start (*Gtk::manage (hbox), true, true, 4);

  return vbox;
  
}

Gtk::VBox*
AboutDialog::create_authors_tab ()
{

  Gtk::VBox *vbox = new Gtk::VBox (false, 4);
  vbox->set_border_width (4);

  Glib::RefPtr<Gtk::TextBuffer> text_buffer = Gtk::TextBuffer::create ();

  Gtk::ScrolledWindow *scrolled_window = new Gtk::ScrolledWindow ();
  scrolled_window->set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
  scrolled_window->set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);

  Gtk::TextView *text_view = new Gtk::TextView ();
  text_view->set_editable (false);
  text_view->set_size_request (520, 200);
  text_view->set_left_margin (4);

  text_buffer->set_text (psz_authors);

  text_view->set_buffer (text_buffer);

  scrolled_window->add (*Gtk::manage (text_view));

  vbox->pack_start (*Gtk::manage (scrolled_window));

  return vbox;
  
}

Gtk::VBox*
AboutDialog::create_thanks_tab ()
{

  Gtk::VBox *vbox = new Gtk::VBox (false, 4);
  vbox->set_border_width (4);

  Glib::RefPtr<Gtk::TextBuffer> text_buffer = Gtk::TextBuffer::create ();

  Gtk::ScrolledWindow *scrolled_window = new Gtk::ScrolledWindow ();
  scrolled_window->set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
  scrolled_window->set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);

  Gtk::TextView *text_view = new Gtk::TextView ();
  text_view->set_editable (false);
  text_view->set_size_request (520, 200);
  text_view->set_left_margin (4);

  Gtk::Label *label = new Gtk::Label (_("We would like to thank the whole "
                "community, the testers, our users and the following people "
                "(and the missing ones...) for their collaboration to "
                "provide the best software." ));
  label->set_line_wrap (true);
  label->set_size_request (520);
  vbox->pack_start (*Gtk::manage (label), false, -1);

  text_buffer->set_text (psz_thanks);

  text_view->set_buffer (text_buffer);

  scrolled_window->add (*Gtk::manage (text_view));

  vbox->pack_start (*Gtk::manage (scrolled_window));

  return vbox;
  
}

Gtk::VBox*
AboutDialog::create_license_tab ()
{

  Glib::RefPtr<Gtk::TextBuffer> text_buffer = Gtk::TextBuffer::create ();

  Gtk::ScrolledWindow *scrolled_window = new Gtk::ScrolledWindow ();
  scrolled_window->set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
  scrolled_window->set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);

  Gtk::TextView *text_view = new Gtk::TextView ();
  text_view->set_editable (false);
  text_view->set_size_request (520, 200);
  text_view->set_left_margin (4);

  text_buffer->set_text (psz_authors);

  text_view->set_buffer (text_buffer);

  Gtk::VBox *vbox = new Gtk::VBox (false, 4);
  vbox->set_border_width (4);

  text_buffer->set_text (psz_license);

  text_view->set_buffer (text_buffer);

  scrolled_window->add (*Gtk::manage (text_view));

  vbox->pack_start (*Gtk::manage (scrolled_window));

  return vbox;
  
}

